package ceha.util;

import ceha.application.CEHA;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JFrame;

public class Mysql {

    public JFrame ceha;
    private String message;
    private String url;
    private String dbName;
    private String driver;
    private String userName;
    private String password;
    private CEHA cehalogin;

    public Mysql(CEHA main) {
        this.cehalogin = main;
    }

    public Connection Connect() throws IOException {
//        url = "jdbc:mysql://localhost:3306/";
//        dbName = "ceha";
//        driver = "com.mysql.jdbc.Driver";
//        userName = "root";
//        password = "";
        Connection conn = null;
        try {
            Class.forName(driver).newInstance();
            conn = DriverManager.getConnection(url + dbName, userName, password);
        } catch (Exception e) {
//            e.printStackTrace();
            new OkDialog(cehalogin, " Problème MySql ! ",true).setVisible(true);
        }
        return conn;
    }

    public void setDbName(String dbName) {
        this.dbName = dbName;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }
}
